using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
using SystemFrameworks;
using Common;
using Microsoft.ApplicationBlocks;
using BusinessRules;
using DataAccess;
using Microsoft.ApplicationBlocks.Data;

namespace BusinessRules
{
    public class SigProAccionDemografica
    {
        #region variables

        private const String PAZ_ID_PARAM = "@PAZ_ID";
        private const String VAL_ID_PARAM = "@VAL_ID";

        private const String PDM_CANTIDAD_PARAM = "@PDM_CANTIDAD";
        private const String PDM_FUENTE_PARAM = "@PDM_FUENTE";
        
        private string _CadenaConexion;

        #endregion

        #region propiedades

        public string CadenaConexion
        {
            get { return _CadenaConexion; }
            set { _CadenaConexion = value; }
        }

        public SigProAccionDemografica(string strCadenaConecxion)
        {
            CadenaConexion = strCadenaConecxion;
        }

        #endregion

        #region AdicionarSigProAccionDemografica

        public int AdicionarSigProAccionDemografica(SigProAccionDemograficaData objDS, params SqlTransaction[] objTransaction)
        {
            DataTable objDT = objDS;
            int intReturn = 0;
            try
            {
                foreach (DataRow objRow in objDT.Rows)
                {

                    SqlParameter param0 = new SqlParameter(VAL_ID_PARAM, SqlDbType.Decimal);
                    SqlParameter param1 = new SqlParameter(PAZ_ID_PARAM, objRow[SigProAccionDemograficaData.PAZ_ID_FIELD]);
                    SqlParameter param2 = new SqlParameter(PDM_CANTIDAD_PARAM, objRow[SigProAccionDemograficaData.PDM_CANTIDAD_FIELD]);
                    SqlParameter param3 = new SqlParameter(PDM_FUENTE_PARAM, objRow[SigProAccionDemograficaData.PDM_FUENTE_FIELD]);
                    
                    param0.Direction = ParameterDirection.Output;
                    SqlParameter[] parameters = {param0, param1, param2, param3};
                    if (objTransaction.Length == 0)
                    {
                        intReturn = SqlHelper.ExecuteNonQuery(CadenaConexion, CommandType.StoredProcedure,
                                                              "PAS_ADICIONAR_SIG_PRG_ACCION_DEMOGRAFIA", parameters);
                    }
                    else
                    {
                        intReturn = SqlHelper.ExecuteNonQuery(objTransaction[0], CommandType.StoredProcedure,
                                                              "PAS_ADICIONAR_SIG_PRG_ACCION_DEMOGRAFIA", parameters);
                    }


                }

            }
            catch (SqlException sqlEx)
            {
                throw new ApplicationExceptionManager(Utilidad.DisplaySqlErrors(sqlEx, "Usuarios"), sqlEx);
            }
            catch (Exception ex)
            {
                throw new ApplicationExceptionManager(Utilidad.TraerMensaje("gmsgErrorInsertar", "Usuarios"), ex);
            }

            return intReturn;
        }

        #endregion

        #region SigProAccionDemograficaData

        public SigProAccionDemograficaData consultarPazId(string strPazId)
        {
            SqlParameter param1 = new SqlParameter(PAZ_ID_PARAM, strPazId);
            SqlParameter[] parameters = new SqlParameter[] { param1 };
            SigProAccionDemograficaData objSigProAccionDemograficaData = new SigProAccionDemograficaData();
            SqlHelper.ExecuteDataTable(CadenaConexion, CommandType.StoredProcedure, "PAS_CONSULTAR_SIG_PRG_ACCION_DEMOGRAFIA_PAZ_ID", objSigProAccionDemograficaData, parameters);
            return objSigProAccionDemograficaData;
        }

        #endregion

        #region Eliminar

        public int Eliminar(string strID, params SqlTransaction[] objTransaction)
        {
            int resultado;
            SqlParameter param1 = new SqlParameter(PAZ_ID_PARAM, strID);
            SqlParameter[] parameters = new SqlParameter[] { param1 };
            if (objTransaction.Length == 0)
            {
                resultado = SqlHelper.ExecuteNonQuery(CadenaConexion, CommandType.StoredProcedure,
                                                      "PAS_ELIMINAR_SIG_PRG_ACCION_DEMOGRAFIA", parameters);
            }
            else
            {
                resultado = SqlHelper.ExecuteNonQuery(objTransaction[0], CommandType.StoredProcedure,
                                                      "PAS_ELIMINAR_SIG_PRG_ACCION_DEMOGRAFIA", parameters);
            }
            return resultado;
        }

        #endregion

    }
}
